package com.yz.constant;


import java.io.Serializable;

/**
 * @author Administrator
 * @param <T>
 */
public class R<T> implements Serializable {

    private static final long serialVersionUID = 1L;
    /**
     * 返回码
     */
    private Integer code;

    /**
     * 返回描述
     */
    private String msg;

    private T data;

    public R() {
    }

    public R(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }


    public R(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public R(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    public static R error() {
        return error(Constant.result_code_error, Constant.result_msg_error);
    }

    public static R error(String msg) {
        return error(Constant.result_code_error, msg);
    }

    public static R error(int code, String msg) {
        return new R(code,msg);
    }

    public static R ok() {
        return new R(Constant.result_code_succ, Constant.result_msg_succ);
    }

    public static R ok(String msg) {
        return new R(Constant.result_code_succ, msg);
    }

    public static <T> R<T> okData(T data) {
        return new R(Constant.result_code_succ, Constant.result_msg_succ, data);
    }

    public static boolean ifSucc(R r){
        return Constant.result_code_succ == r.getCode();
    }
    public static boolean ifError(R r){
        return Constant.result_code_succ != r.getCode();
    }

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public T getData() {
        return data;
    }

}
